﻿@{
    ViewBag.Title = "部门管理";
    Layout = "~/Views/Shared/_TreeLayout.cshtml";
}

<div class="heading-buttons">


    <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
        <h1 class="page-title txt-color-blueDark"><i class="fa  fa-gear "></i>
            部门管理
			
        </h1>
    </div>
    <div class="buttons pull-right">

        <button type="button" class="btn btn-success btn-labeled " id="btnSyspartAdd"
            data-bind="click: $root.AddNewNode">
            <span class="btn-label"><i class="glyphicon glyphicon-plus"></i>
            </span>添加结点</button>

        <button type="button" class="btn btn-primary btn-labeled " id="btnSyspartDel"
            data-bind="click: $root.DelNode">
            <span class="btn-label"><i class="glyphicon glyphicon-remove"></i>
            </span>删除结点</button>


    </div>
    <div style="clear: both;">
    </div>
</div>
<!--/Operation-->


<hr class="separator" />
<!-- Bread crumb is created dynamically -->



<div class="row">

    <div class="col-sm-4" style="margin-bottom: 5px; margin-top: 5px;">
        <div class="well well-light well-sm no-margin no-padding treeContent">
            <!--Syspart tree-->
            <ul id="SyspartTree" class="ztree">
            </ul>


        </div>

    </div>
    <!-- end col-sm-61 -->
    <!--/Syspart tree-->







    <!--Syspart  information-->
    <div class="col-sm-8" style="margin-bottom: 5px; margin-top: 5px;">
        <div class="well well-light well-sm no-margin no-padding treeContent">
            <input type="hidden" id="hidId" />
            <form class="form-horizontal" id="frmSyspart" data-bind="with: NodeValue">

                <fieldset>
                    <div class="row" style="border-bottom: dashed 1px; margin-bottom: 10px;">
                        <h3 style="padding: 10px 0 10px 10px; float: left;"><strong>详细信息</strong></h3>
                        <div class="buttons pull-right">


                            <button type="button" id="btnSyspartUpdate" class="btn btn-success btn-labeled " style="margin-top: 5px;" data-bind="click: $root.updateNode">
                                <span class="btn-label"><i class="fa fa-save"></i>
                                </span>保存</button>

                        </div>
                    </div>

                    <div style="clear: both;" />


                    <div class='form-group'>
                        <label class='col-md-2 control-label' style='margin-bottom: 3px;'>部门名:</label>
                        <div class='col-md-9'>
                            <input type='text' id='txtbSPartName' name='txtbSPartName' placeholder='' class='form-control' data-bind='value:SPartName' />                            
                        </div>

                    </div>
                    <div class='form-group'>
                        <label class='col-md-2 control-label' style='margin-bottom: 3px;'>类型:</label><div class='col-md-9'>
                            <input type='text' id='txtbIType' name='txtbIType' placeholder='' class='form-control' data-bind='value:IType' />
                        </div>
                    </div>
                    <div class='form-group'>
                        <label class='col-md-2 control-label' style='margin-bottom: 3px;'>部门描述:</label><div class='col-md-9'>
                            <textarea id='txtbSScript' name='txtbSScript' placeholder='' class='form-control' data-bind='value:SScript'> </textarea>
                        </div>
                    </div>


                    <input type='hidden' disabled="disabled" id='txtbIParentId' name='txtbIParentId' placeholder='' class='form-control' data-bind='value:IParentId' />

                    <div class='form-group'>
                        <label class='col-md-2 control-label' style='margin-bottom: 3px;'>备注:</label><div class='col-md-9'>
                            <input type='text' id='txtbSMemo' name='txtbSMemo' placeholder='' class='form-control' data-bind='value:SMemo' />
                        </div>
                    </div>

                     <input type='hidden' id='txtbIOwer' name='txtbIOwer' placeholder='' class='form-control' data-bind='value:IOwer' />
               
                    <div class='form-group'>
                        <label class='col-md-2 control-label' style='margin-bottom: 3px;'>是否临时:</label><div class='col-md-9'>
                            <input type='text' id='txtbIIsTmp' name='txtbIIsTmp' placeholder='' class='form-control' data-bind='value:IIsTmp' />
                        </div>
                    </div>


                    <input type='hidden' id='txtbILevel' name='txtbILevel' placeholder='' class='form-control' data-bind='value:ILevel' />

                </fieldset>

            </form>



        </div>
    </div>


</div>

<!-- end row -->
<!--/Syspart information-->


<script type="text/javascript">

    var viewModel;
    $(function () {


        var options = {

            renderDiv: $("#SyspartTree"),
            hidId: $("#hidId"),
            frmElement: $("#frmSyspart"),



            UpdateBtn: $("#btnSyspartUpdate"),
            AddBtn: $("#btnSyspartAdd"),
            DelBtn: $("#btnSyspartDel"),


            //节点数据
            NodeValue: ko.observable({

                Id: 0, SPartName: '', IType: 0, SScript: '', IParentId: 0, SMemo: '', IOwer: 0, IIsTmp: 0, ILevel: 0

            }),

            //用户查询URL
            dataQueryUrlAccessor: function () { return "/api/Syspart/TreeAll"; },

            //添加用户URL
            dataAddUrlAccessor: function (key) { return "/api/Syspart/AddTreeNode/" + key; },
            dataUpdateAccessor: function (key) { return "/api/Syspart/Put/" + key; },
            dataDeleteAccessor: function (key) {


                return "/api/Syspart/Delete/" + key;

            },
            dataNodeSelect: function (id) {
                return "/api/Syspart/get/" + id;
            }

			, showDlgBefore: function () {
			    //显示对话框之前

			}
                , showDetailEnd: function (data) {


                }
             , changeEnd: function (key, event) {
                 //对话框保存的后置事件
             }, initEd: function () {
                 //gird初始化的后置事件 信息

             }

        };

        viewModel = new ViewModel(options);


        viewModel.init();
        ko.applyBindings(viewModel);


        //$("#myform").validate({ , debug: true })

        options.frmElement.validate({
            rules: {

                txtbSPartName: { required: true, maxlength: 50 },
                txtbIType: { required: true, digits: true },
                txtbSScript: { maxlength: 50 },
                txtbSMemo: { maxlength: 50 },
                txtbIIsTmp: { digits: true },

            },
            messages: {

                txtbSPartName: { required: '必填项', maxlength: '最大长度为50' },
                txtbIType: { required: '必填项', digits: '必须是整数' },
                txtbSScript: { maxlength: '最大长度为50' },
                txtbSMemo: { maxlength: '最大长度为50' },
                txtbIIsTmp: { digits: '必须是整数' },

            },
            highlight: function (element) {
                $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            unhighlight: function (element) {
                $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
            },
            errorElement: 'span',
            errorClass: 'help-block'

        });

    });

</script>
